package com.bear.sgg.springboot_11_cache.Controller;

import com.bear.sgg.springboot_11_cache.entity.Employee;
import com.bear.sgg.springboot_11_cache.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassNmae EmployeeController
 * @Description TODO
 * @Author bear
 * @Date 2020/3/17 0017 上午 10:07
 */
@RestController
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @GetMapping(value = "/emp/{id}")
    public Employee selectEmpById(@PathVariable("id") Integer id) {
        return employeeService.selectEmpById(id);
    }

    @GetMapping(value = "/emp/{id}/{lastName}/{email}/{gender}/{dId}")
    public Employee updateEmp(Employee employee) {
        return employeeService.updateEmp(employee);
    }

    @GetMapping(value = "/deleteEmp/{id}")
    public String deleteEmpById(@PathVariable("id") Integer id) {
        Integer result = employeeService.deleteEmpById(id);
        return result > 0 ? "success" : "fault";
    }

    @GetMapping(value = "/emp/lastName/{lastName}")
    public Employee selectEmpByLastName(@PathVariable("lastName") String lastName) {
        return employeeService.selectEmpByLastName(lastName);
    }
}
